package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IUnitNameDao;
import com.hy.erp.inventory.pojo.UnitName;
import com.hy.erp.inventory.pojo.interfaces.IUnitName;
import com.hy.erp.inventory.service.interfaces.IUnitNameService;
@Name("unitNameService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class UnitNameService
							extends
							AbstractBusinessService < IUnitName >
																	implements
																	IUnitNameService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-11；时间：下午05:25:55</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														- 5870705964919981892L ;

	public CopyOfUnitNameService(){super ( );}

	@ Override
	public boolean addUnitName (
									UnitName unitName )
	{
		if(unitName==null)
		{
			return true;
		}
		else
		{
			IUnitNameDao iUnitNameDao=(IUnitNameDao) this.getDao(IUnitName.class);
			IUnitName iUnitName= unitName;
			return iUnitNameDao.persist(iUnitName);
		}
	}

	@ Override
	public Integer removeUnitName (
									String [ ] unitNameIds )
	{
		if ( ( null == unitNameIds )
			     || ( unitNameIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IUnitNameDao dao=( IUnitNameDao ) this.getDao ( IUnitName.class );
				return dao.remove ( unitNameIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyUnitName (
									UnitName unitName )
	{
		if ( ( null == unitName ) || ( null == unitName.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IUnitNameDao dao=( IUnitNameDao ) this.getDao ( IUnitName.class );
			IUnitName iUnitName= unitName;
			
			if ( null == iUnitName )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iUnitName )!=null) ;
		}
	}

	@ Override
	public String [ ] addUnitName (
									Object [ ] unitNames )
	{
		IUnitNameDao dao=( IUnitNameDao ) this.getDao ( IUnitName.class );
		UnitName[] names=new UnitName[unitNames.length];
		for ( int i =
						0 ; i < unitNames.length ; i ++ )
		{
			UnitName unitName=( UnitName ) unitNames[i];
			names[i]=unitName;
		}
		return dao.persist ( names ) ;
	}

	@ Override
	public List < IUnitName > getAllUnitName ( )
	{
		IUnitNameDao dao=( IUnitNameDao ) this.getDao ( IUnitName.class );
		return dao.find ( ) ;
	}

	@ Override
	public String [ ] modifyUnitName (
										Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			IUnitNameDao dao=( IUnitNameDao ) this.getDao ( IUnitName.class );
			UnitName[] names=new UnitName[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	UnitName name=( UnitName ) objects[i];
            	names[i]=name;
            }
			
			return dao.merge ( names );
		}
	}

}
